<?php


class PhysicalStoreController extends BaseController
{

    use \app\library\traits\Restful;

    /**
     * 获取分类
     */
    public function getCatListAction() {
        return $this->returnSuccess((new PhysicalStoreModel())->getCatText());
    }

    /**
     * 获取内容
     */
    public function read(){
        $cat_text = $this->getRequest()->getQuery("cat_text");
        $PhysicalStoreModel = new PhysicalStoreModel();
        $longitude = floatval($this->getRequest()->getQuery("longitude"));
        $latitude = floatval($this->getRequest()->getQuery("latitude"));
        if (empty($cat_text) || !$PhysicalStoreModel->hasCatText($cat_text) || empty($latitude) || empty($longitude)) {
            return $this->noParams();
        }
        $page = $this->getRequest()->getQuery("page", 1);
        $pagesize = $this->getRequest()->getQuery("pagesize", 15);

        $lists = $PhysicalStoreModel->findListByCategoryOrderDistance($cat_text, $page, $pagesize, $longitude, $latitude);
        $data = [
            'page' => $page,
            'loadend' => 0,
            'lists' => $lists
        ];
        if (count($lists) < $pagesize) {
            $data['loadend'] = 1;
        }
        return  $this->returnSuccess($data);
    }


}